﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace FinancePortal.Business.Infraestructure
{
    public static class ExtensionMethods
    {
        public static bool IsNullOrEmpty<T>(this IEnumerable<T> source)
        {
            return source == null || source.Count() == 0;
        }

        public static IEnumerable<TOutput> ConvertAll<T, TOutput>(this IEnumerable<T> enumerable, Converter<T, TOutput> converter)
        {
            if (enumerable == null)
            {
                throw new ArgumentNullException("enumerable");
            }

            if (converter == null)
            {
                throw new ArgumentNullException("converter");
            }

            int size = enumerable.Count();

            List<TOutput> list = new List<TOutput>(size);

            for (int i = 0; i < size; i++)
            {
                list.Add(converter(enumerable.ElementAt(i)));
            }

            return list;
        }
    }
}
